package Operation;

import BookRack.Book;
import BookRack.BookRack;

import java.util.Scanner;

public class DeleteBookOperation implements IOperation{
    @Override
    public void work(BookRack bookRack) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("输入书名来删除 ");
        String title = scanner.nextLine();

        boolean found = false;
        for (Book book : bookRack.getBooks()) {
            if (book.getTitle().equalsIgnoreCase(title)) {
                bookRack.getBooks().remove(book);
                System.out.println("成功删除 " + book.getTitle() );
                found = true;
                break; // Exit loop after deleting the book
            }
        }

        if (!found) {
            System.out.println("未找到名为'" + title + "'的书");
        }
    }
}
